package com.graduation.fq.student.Logic;

import com.graduation.fq.student.Args.AlterLoginEventArgs;
import com.graduation.fq.student.Process.AlterPwdProcess;
import com.graduation.fq.student.Process.LoginProcess;
import com.graduation.fq.student.interfaces.EventListener;
import com.graduation.fq.student.interfaces.ResponseListener;

/**
 * @author jifang
 * @version 2016/5/23.
 */
public class LoginAndAlterPwdLogic extends BaseLogic {

    private static LoginAndAlterPwdLogic instance;

    public static LoginAndAlterPwdLogic getInstance() {
        if (instance == null) {
            instance = new LoginAndAlterPwdLogic();
        }
        return instance;
    }

    public void login(String id, String pwd, final EventListener listener) {
        final LoginProcess process = new LoginProcess();
        process.setId(id);
        process.setPwd(pwd);
        process.runGet(new ResponseListener() {
            @Override
            public void onResponse(String requestId) {
                AlterLoginEventArgs args = new AlterLoginEventArgs(process.getStatus(), process.isLogin(), process.getId());
                fireEvent(args, listener);
            }
        });
    }

    public void alterPwd(String id, String oldPwd, String newPwd, final EventListener listener) {
        final AlterPwdProcess process = new AlterPwdProcess();
        process.setId(id);
        process.setOldPwd(oldPwd);
        process.setNewPwd(newPwd );
        process.runGet(new ResponseListener() {
            @Override
            public void onResponse(String requestId) {
                AlterLoginEventArgs args = new AlterLoginEventArgs(process.getStatus());
                args.setLogin(process.isLogin());
                fireEvent(args, listener);
            }
        });
    }
}
